﻿Imports System.Xml
Imports Idml.Spreads

Public Class SpreadLoader

	Function LoadSpreads(SpreadFiles As String()) As List(Of Spread)
		Dim Result As New List(Of Spread)

		For Each file As String In SpreadFiles
			Result.Add(LoadSpread(file))
		Next

		Return Result
	End Function

	Private Function LoadSpread(file As String) As Spread
		Dim textreader As New IO.StreamReader(file)
		Dim reader As XmlReader

		reader = XmlReader.Create(textreader, New XmlReaderSettings() With {
		  .CloseInput = True,
		  .ConformanceLevel = ConformanceLevel.Document,
		  .DtdProcessing = DtdProcessing.Ignore,
		  .IgnoreComments = True,
		  .IgnoreProcessingInstructions = False,
		  .IgnoreWhitespace = True,
		  .ValidationType = ValidationType.None})

		reader.ReadStartElement("idPkg:Spread")

		Dim spread As Spread
		spread = spread.ReadXml(reader)

		reader.Close()

		Return spread
	End Function

End Class
